'''
 * @ author     ：廖传港
 * @ date       ：Created in 2020/11/9 20:29
 * @ description：
 * @ modified By：
 * @ ersion     : 
 * @File        : fit.py 
'''
import numpy as np
from com.lcg.version6 import Loading_pictures as lp
from com.lcg.version6 import trainModelByTeacher as tr


# def MaxMinNormalization(x,Max,Min):
# 	x = (x - Min) / (Max - Min);
# 	return x;

X, Y = lp.loaddata("D:/python/data/")
print(X[0].shape)
# X = MaxMinNormalization(X,1,0)


dnn=tr.DNN()
dnn.Add(tr.CNN2D_MultiLayer(4,4,stride=4,nFilter=10))
dnn.Add(tr.DMaxPooling2D(4,4))
dnn.Add(tr.CNN2D_MultiLayer(4,4,stride=2,nFilter=5))
dnn.Add(tr.DMaxPooling2D(4,4))
dnn.Add(tr.DFlatten())
dnn.Add(tr.DDense(20,'sigmoid'))
dnn.Add(tr.DDense(10,'relu'))
dnn.Compile(lossMethod='SoftmaxCrossEntropy')
dnn.Fit(X[0:10,:], Y[0:10,],100)

# predictY：预测Y BatchPredict批预测
# predictY = dnn.BatchPredict(X[50:80,])
predictY = dnn.BatchPredict(X[10:20,:])

print("predictY=", predictY)
predictYY = np.array([np.argmax(one_hot) for one_hot in predictY])

realY = Y[10:20]
print("realY=",realY)

realYY = np.array([np.argmax(one_hot) for one_hot in realY])

from sklearn.metrics import accuracy_score

# accuracy_score(predictYY, realYY)

print("准确数=",accuracy_score(predictYY, realY, normalize=False))
print("准确率=",accuracy_score(predictYY, realY))